import React,{useState,useEffect,useRef} from 'react';
// Capture value
const App = () => {
  let [count,upCount] = useState(0);
  useEffect(()=>{
    let timerId = setInterval(()=>{
      upCount(c=>c+1); 
      getCount();// 0
    },1000);
    return ()=>{
      clearTimeout(timerId);
    }
  },[])
  const getCount = ()=>{
    // console.log(ref.current);
    console.log(count);
  }
  let ref = useRef();
  ref.current = count;
  return (
    <div>
      <h1>{count}</h1>
    </div>
  );
}

export default App;
